package kevin.hbase.controller;

import kevin.hbase.analyse.gps.DelGpsManager;
import kevin.hbase.analyse.stop.StopManager;
import kevin.hbase.common.HttpResult;
import kevin.hbase.service.HbaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/hbase")
public class HbaseController {
    @Autowired
    private HbaseService hbaseService;
    @Autowired
    private StopManager stopManager;

    @Autowired
    private DelGpsManager delGpsManager;

    @RequestMapping(value = "/del", method = RequestMethod.GET)
    public HttpResult delGps(String deviceId, String gpsTime) throws Exception {
        hbaseService.delGps(deviceId, gpsTime);
        return HttpResult.success();
    }

    @RequestMapping(value = "/last", method = RequestMethod.GET)
    public HttpResult lastGps(String callLetter) throws Exception {
        return HttpResult.success(hbaseService.getLastGps(callLetter));
    }

    @RequestMapping(value = "/history", method = RequestMethod.GET)
    public HttpResult history(String callLetter, String startTime, String endTime) throws Exception {
        return HttpResult.success(hbaseService.getHistoryGps(callLetter, startTime, endTime));
    }

    @RequestMapping(value = "/stop", method = RequestMethod.GET)
    public HttpResult stop() throws Exception {
        stopManager.start();
        return HttpResult.success();
    }

    @RequestMapping(value = "/delGps", method = RequestMethod.GET)
    public HttpResult delGps() throws Exception {
        delGpsManager.start();
        return HttpResult.success();
    }
}
